package cn.tedu.yl.TJxm.service;

import cn.tedu.yl.TCLX.mapper.nxtcMapper;
import cn.tedu.yl.TCLX.pojo.nxtc;
import cn.tedu.yl.TJxm.mapper.TJXMMapper;
import cn.tedu.yl.TJxm.pojo.TJXM;
import cn.tedu.yl.base.response.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.SecureRandom;
import java.util.List;

@Service
public class TJXMService {

    @Autowired
    private TJXMMapper tjxmMapper;

    @Autowired
    private nxtcMapper nxtcMapper1;
    public PageData getAllTJXM() {
        PageData pageData = new PageData();
        pageData.setList(findALl());
        pageData.setTotal(tjxmMapper.findAll().size());
        return pageData;
    }

    private List findALl() {
        return tjxmMapper.findAll();
    }

    public void createTJXM(TJXM tjxm) {
        tjxm.setProjectId(setpackageId());
        tjxmMapper.save(tjxm);
    }

    private Integer setpackageId() {
        SecureRandom secureRandom = new SecureRandom();
        Integer packageId = secureRandom.nextInt(1000000000);
        return packageId;
    }

    public void deleteTJXM(Long id) {
        tjxmMapper.deleteById(id);
    }

    public List<nxtc> selectBySSTC() {
        return nxtcMapper1.findAll();
    }
}
